package com.zzh.study.handler;

import com.zzh.study.model.po.WebFluxDemoPO;
import com.zzh.study.service.WebFluxDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.reactive.TransactionalOperator;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * @PackageName:com.zzh.study.handler
 * @ClassName:MyWebHandler
 * @Description:
 * @author:zhangzhanheng
 * @date: 2020/12/18 18:32
 */
@Component
public class MyWebHandler {

    @Autowired
    private WebFluxDemoService webFluxDemoService;

    @Autowired
    private TransactionalOperator transactionalOperator;

    @Autowired
    private WebClient.Builder  builder;

    /**
     * @Author zhangzhanheng
     * @Description //保存
     * @Date 19:12 2020/12/18
     * @Param [serverRequest]
     * @return reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
     **/
    public Mono<ServerResponse> save(ServerRequest serverRequest) {
        return serverRequest.bodyToMono(WebFluxDemoPO.class)
                .flatMap(i -> webFluxDemoService.save(i))
                .flatMap(p -> ServerResponse.ok().bodyValue(p));
    }


}
